<template>
  <view class="order-update">
    <view class="order_update_view">
		<view class="pictrue">
			<image :src="orderInfo.cartInfo[0].productInfo.image"/></image>
		</view>
		<view class="order_form">
			<view class="title">{{orderInfo.cartInfo[0].productInfo.storeName }}</view>
			<view class="totalNum">数量：{{orderInfo.totalNum }}</view>
			<view class="inputLine">
				<view class="text">单价：</view>
				<view class="text_input"><input type="text" v-model="price"/></view>
			</view>
			<view class="inputLine">
				<view class="text">金额：</view>
				<view class="text_input"><input type="text" v-model="totalPrice"/></view>
			</view>
		</view>
		<view class="order_form_bottom_line"></view>
		<view class="order_form_collect_info">优惠后金额<label>￥{{yhTotalPrice}}</label>已优惠<label>￥{{devYhPrice}}</label></view>
	</view>
	<view class="order_add_gift_view">
		<view class="order_add_btn" @click="goOrderGift()">添加赠品</view>
		<view class="gift_list"  v-for="(item, giftListIndex) in giftList" :key="giftListIndex">
			<view class="pictrue">
				<image :src="item.image"/></image>
			</view>
			<view class="gift_info">
				<view class="gift_title">{{item.storeName }}</view>
				<view class="gift_text">数量：{{item.totalnum }}</view>
				<view class="gift_text">单价：￥{{item.price }}</view>
			</view>
			<view class="gify_delete_btn">-</view>
		</view>
		<view class="order_form_bottom_line"></view>
		<view class="order_total_collect">
			<view class="inputLine">
				<view class="text">整单金额：</view>
				<view class="text_input"><input type="text" v-model="zdprice"/></view>
			</view>
			<view class="inputLine2">
				<view class="text">整单优惠后金额：</view>
				<view class="text2">￥{{yhTotalPrice}}</view>
			</view>
			<view class="inputLine2">
				<view class="text">整单优惠：</view>
				<view class="text2">￥{{devYhPrice}}</view>
			</view>
			<view class="inputLine2">
				<view class="text">总优惠：</view>
				<view class="text2">￥{{zyhprice}}</view>
			</view>
			
		</view>
		<view class="order_add_btn2">确定</view>
	</view>
	
  </view>
</template>

<script>
 
  import {
    orderDetail
  } from "@/api/order";
 
  export default {
    data: function () {
      return {
		price:0,
		zdprice:0,//整单金额
		zyhprice:0,//总优惠
		totalPrice:'',
		yhTotalPrice:'',
		devYhPrice:'',
		giftList: [],
        id: "",
        orderInfo: {
          _status: {},
        },
       
      };
    },
    computed: {
      
    },
    mounted: function () {
      this.id = this.$yroute.query.id;
	  
	 
      this.getDetail();
	  
    },
    methods: {
      getDetail() {
        const id = this.id;
        if (!id) {
          uni.showToast({
            title: "订单不存在",
            icon: "none",
            duration: 2000,
          });
          return;
        }
        orderDetail(id)
          .then((res) => {
            this.orderInfo = res.data;
			console.log("-----------111111111111111111111111111-----------------");
			this.price=this.orderInfo.cartInfo[0].productInfo.price;
			this.totalPrice=this.orderInfo.totalPrice;
			console.log(uni.getStorageSync("giftList"));
			//添加赠品后
			if(this.$yroute.query.price){
				this.price=this.$yroute.query.price;
				this.giftList=uni.getStorageSync("giftList")
			}
          })
          .catch((err) => {
           
          });
      },
	  goOrderGift(){
		  var that=this
		  this.$yrouter.push({
		    path: "/pages/agent/Order/OrderGift/index",
		    query: {
		      id: that.orderInfo.orderId,
			  price:that.price
		    },
		  });
	  }
    
    },
	watch:{
		
		price(){
			this.totalPrice=this.price*this.orderInfo.totalNum;
			this.yhTotalPrice=this.totalPrice;
			this.devYhPrice=this.orderInfo.cartInfo[0].productInfo.price*this.orderInfo.totalNum-this.yhTotalPrice;
			var gift_total_price=0;
			if(this.giftList.length>0){
				this.giftList.forEach((item) => {
					gift_total_price+=item.totalnum*item.price;
				});
			}
			this.zdprice=this.yhTotalPrice+gift_total_price;
			this.zyhprice=this.devYhPrice+gift_total_price;
		}
	},
  };
</script>

<style scoped lang="less">
  .geoPage {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    z-index: 10000;
  }

  .order-details .writeOff {
    background-color: #fff;
    margin-top: 0.13 * 100rpx;
    padding-bottom: 0.3 * 100rpx;
  }

  .order-details .writeOff .title {
    font-size: 0.3 * 100rpx;
    color: #282828;
    height: 0.87 * 100rpx;
    border-bottom: 1px solid #f0f0f0;
    padding: 0 0.3 * 100rpx;
    line-height: 0.87 * 100rpx;
  }

  .order-details .writeOff .grayBg {
    background-color: #f2f5f7;
    width: 5.9 * 100rpx;
    height: 3.84 * 100rpx;
    border-radius: 0.2 * 100rpx 0.2 * 100rpx 0 0;
    margin: 0.5 * 100rpx auto 0 auto;
    padding-top: 0.55 * 100rpx;
  }

  .order-details .writeOff .grayBg .pictrue {
    width: 2.9 * 100rpx;
    height: 2.9 * 100rpx;
    margin: 0 auto;
  }

  .order-details .writeOff .grayBg .pictrue img {
    width: 100%;
    height: 100%;
    display: block;
  }

  .order-details .writeOff .gear {
    width: 5.9 * 100rpx;
    height: 0.3 * 100rpx;
    margin: 0 auto;
  }

  .order-details .writeOff .gear img {
    width: 100%;
    height: 100%;
    display: block;
  }

  .order-details .writeOff .num {
    background-color: #f0c34c;
    width: 5.9 * 100rpx;
    height: 0.84 * 100rpx;
    color: #282828;
    font-size: 0.48 * 100rpx;
    margin: 0 auto;
    border-radius: 0 0 0.2 * 100rpx 0.2 * 100rpx;
    text-align: center;
    padding-top: 0.04 * 100rpx;
  }

  .order-details .writeOff .rules {
    margin: 0.46 * 100rpx 0.3 * 100rpx 0 0.3 * 100rpx;
    border-top: 0.01 * 100rpx solid #f0f0f0;
    padding-top: 0.1 * 100rpx;
  }

  .order-details .writeOff .rules .item {
    margin-top: 0.15 * 100rpx;
  }

  .order-details .writeOff .rules .item .rulesTitle {
    font-size: 0.28 * 100rpx;
    color: #282828;
  }

  .order-details .writeOff .rules .item .rulesTitle .iconfont {
    font-size: 0.3 * 100rpx;
    color: #333;
    margin-right: 0.08 * 100rpx;
    margin-top: 0.05 * 100rpx;
  }

  .order-details .writeOff .rules .item .info {
    font-size: 0.28 * 100rpx;
    color: #999;
    margin-top: 0.05 * 100rpx;
  }

  .order-details .writeOff .rules .item .info .time {
    margin-left: 0.2 * 100rpx;
  }

  .order-details .map {
    height: 0.86 * 100rpx;
    font-size: 0.3 * 100rpx;
    color: #282828;
    line-height: 0.86 * 100rpx;
    border-bottom: 0.01 * 100rpx solid #f0f0f0;
    margin-top: 0.13 * 100rpx;
    background-color: #fff;
    padding: 0 0.3 * 100rpx;
  }

  .order-details .map .place {
    font-size: 0.26 * 100rpx;
    width: 1.76 * 100rpx;
    height: 0.5 * 100rpx;
    border-radius: 0.25 * 100rpx;
    line-height: 0.5 * 100rpx;
    text-align: center;
  }

  .order-details .map .place .iconfont {
    font-size: 0.27 * 100rpx;
    height: 0.27 * 100rpx;
    line-height: 0.27 * 100rpx;
    margin: 0.02 * 100rpx 0.03 * 100rpx 0 0;
  }

  .order-details .address .name .iconfont {
    font-size: 0.34 * 100rpx;
    margin-left: 0.1 * 100rpx;
  }
</style>
